/**
 * 
 */
package com.ms.service.module.zone;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.player.Player;
import com.xpec.c4.game.datamanager.ResultNo;
import com.xpec.c4.game.login.async2.DoAfterLoadPlayerAsync;
import com.xpec.c4.message.ConstantCode;

/**
 * 登入 zone 時取得角色資料的 async
 * 
 * @author TW15010
 */
public class LoginZoneGetPlayerAsync extends DoAfterLoadPlayerAsync {
	/** log4j object */
	private static final Log log = LogFactory.getLog(LoginZoneGetPlayerAsync.class);

	/**
	 * 登入 zone 時向 data center 取角色資料帶入的參數
	 */
	private LoginZoneGetPlayerDataFromDCParam param;

	@Override
	public void execute() throws Exception {
		// TODO kevin jb async
		Player player = getLoadPlayer();

		switch (getResultCode()) {
		case ResultNo.OK:
			log.info("Load player from dc success, id: " + getLoadPlayerId());
			break;

		case ResultNo.ACCESS_DENY:
			log.info("Access deny  id: " + getLoadPlayerId());
			break;

		case ResultNo.FAILED:
			log.info("Query failed  id: " + getLoadPlayerId());
			break;

		case ResultNo.DATA_NOT_FOUND:
			log.info("Data not found id: " + getLoadPlayerId());
			break;

		case ResultNo.DB_OPERATION_FAILED:
			log.info("DB operation failed id: " + getLoadPlayerId());
			break;

		default:
			log.info(ConstantCode.getName(ResultNo.class, getResultCode()) + " id: " + getLoadPlayerId());
			break;
		}

		// 將取回的玩家資料轉給 zone
		param.getBasicZone().onLoginZoneGetPlayerDataFromDC(getLoadPlayerId(), player, param.getSessionId());
	}

	public LoginZoneGetPlayerDataFromDCParam getParam() {
		return param;
	}

	public void setParam(LoginZoneGetPlayerDataFromDCParam param) {
		this.param = param;
	}
}
